import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { DrugVO, DrugForm, DrugQuery } from '@/api/pill/drug/types';

/**
 * 查询药品信息列表
 * @param query
 * @returns {*}
 */

// export const listDrug = (query?: DrugQuery): AxiosPromise<{ total: number; rows: DrugVO[] }> => { todo  还是得找方法定义返回类型 这么写没效果
export const listDrug = (query?: DrugQuery): AxiosPromise<DrugVO[]> => {
  return request({
    url: '/pill/drug/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询药品信息详细
 * @param drugId
 */
export const getDrug = (drugId: string | number): AxiosPromise<DrugVO> => {
  return request({
    url: '/pill/drug/' + drugId,
    method: 'get'
  });
};

/**
 * 新增药品信息
 * @param data
 */
export const addDrug = (data: DrugForm) => {
  return request({
    url: '/pill/drug',
    method: 'post',
    data: data
  });
};

/**
 * 修改药品信息
 * @param data
 */
export const updateDrug = (data: DrugForm) => {
  return request({
    url: '/pill/drug',
    method: 'put',
    data: data
  });
};

/**
 * 删除药品信息
 * @param drugId
 */
export const delDrug = (drugId: string | number | Array<string | number>) => {
  return request({
    url: '/pill/drug/' + drugId,
    method: 'delete'
  });
};
